﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class DamageReceiverSphereCollider : DamageReceiverCollider {
    #region Fields

    public Transform sphereCenter;

    public float radius;
    #endregion Fields

    #region Methods

    public void Init(Transform bindTF, float aRadius, LayerMask layerMask) {

        radius = aRadius;

        if(bindTF != null) {
            sphereCenter = bindTF;
        } else {
            sphereCenter = transform;
        }
        layersToHit = layerMask;
        init();
    }

    public override void CheckInsideColliderRay() {
        Collider[] s1 = Physics.OverlapSphere(sphereCenter.position, radius, layersToHit.value);
        AddColliers(s1);
    }

    public override bool PointInsideCollider(Vector3 aPoint) {
        float totalSqrRadius = radius * radius;
        Vector3 sphereCenterPos = sphereCenter.position;
        sphereCenterPos.y = 0;
        aPoint.y = 0;
        return ((aPoint - sphereCenterPos).sqrMagnitude <= totalSqrRadius);
    }

    void OnDrawGizmos() {
        if (DamageReceiverCollider.IsDrawColliderWire == false)
        {
            return;
        }
        Vector3 center = transform.position;
        if(sphereCenter != null) {
            center = sphereCenter.position;
        }

        Gizmos.color = Color.green;

        Gizmos.DrawWireSphere(center, radius);
    }

    #endregion Methods
}